/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package barreirasacscomunicator.connection;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author rjsantos
 */
public class SshTunnels {

    public JSch jsch;
    public Session session;




    public SshTunnels(){



    }

    public void connect() {
             // compute primes larger than minPrime

        InetAddress inetAddress;



        try {


            try {
                //only for development on server LAN
                inetAddress = InetAddress.getByName("naseinadaserver");
            } catch (UnknownHostException ex) {
                inetAddress = InetAddress.getByName("barreirasac.servegame.com");
            }



            //System.out.println(inetAddress.getHostAddress());
            String host=inetAddress.getHostAddress();
            String user="barreirasacs";
            String password="serverb";
            int port=22;


            jsch=new JSch();

            session = jsch.getSession(user, host, port);


            session.setPassword(password);

            MyUserInfo lui=new MyUserInfo();
            session.setUserInfo(lui);
            session.connect();
            session.setTimeout(Integer.MAX_VALUE);
            session.setPortForwardingL(6667,"127.0.0.1",6667);
            session.setPortForwardingL(6668,"127.0.0.1",6668);
            session.setPortForwardingL(6669,"127.0.0.1",6669);


            session.setPortForwardingL(28763,"127.0.0.1",28763);
            session.setPortForwardingL(28764,"127.0.0.1",28764);




            System.out.println("Connected");

         } catch (UnknownHostException ex) {
            Logger.getLogger(SshTunnels.class.getName()).log(Level.SEVERE, null, ex);
         } catch (JSchException ex) {
                Logger.getLogger(SshTunnels.class.getName()).log(Level.SEVERE, null, ex);
         }



    }



}
